/**
* @file tensor_desc_internal.cpp
*
* Copyright (C) Huawei Technologies Co., Ltd. 2023. All Rights Reserved.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "acl/acl_base.h"
#include "tensor_desc_internal.h"
#include "framework/executor_c/ge_executor_types.h"
#include <stdlib.h>

aclDataBuffer *aclCreateDataBuffer(void *data, size_t size) {
  DataBuffer *dataBuffer = (DataBuffer *)malloc(sizeof(DataBuffer));
  if (dataBuffer == NULL) {
    return NULL;
  }
  dataBuffer->data = data;
  dataBuffer->length = size;
  return (aclDataBuffer *)dataBuffer;
}

aclError aclDestroyDataBuffer(const aclDataBuffer *dataBuffer) {
  DataBuffer *geDatabuffer = (DataBuffer *)dataBuffer;
  if (geDatabuffer == NULL) {
    return ACL_ERROR_INVALID_PARAM;
  }
  free(geDatabuffer);
  return ACL_SUCCESS;
}

void *aclGetDataBufferAddr(const aclDataBuffer *dataBuffer) {
  if (dataBuffer == NULL) {
    return NULL;
  }
  return ((DataBuffer *)dataBuffer)->data;
}

size_t aclGetDataBufferSizeV2(const aclDataBuffer *dataBuffer) {
  if (dataBuffer == NULL) {
    return 0UL;
  }
  return (size_t)((DataBuffer *)dataBuffer)->length;
}